﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using Boggle;

namespace Boggle.Client
{
    /// <summary>
    /// Interaction logic for OptionsWindow.xaml
    /// </summary>
    public partial class OptionsWindow : Window
    {
        public IBoggleDictionary SelectedDictionary
        {
            get { return (IBoggleDictionary)GetValue(SelectedDictionaryProperty); }
            set { SetValue(SelectedDictionaryProperty, value); }
        }

        public static readonly DependencyProperty SelectedDictionaryProperty =
            DependencyProperty.Register("SelectedDictionary", typeof(IBoggleDictionary), typeof(OptionsWindow), new UIPropertyMetadata(null));

        public ObservableCollection<IBoggleDictionary> Dictionaries { get; private set; }

        public OptionsWindow(IList<IBoggleDictionary> dictionaries, IBoggleDictionary selectedDictionary)
        {
            if (dictionaries == null)
            {
                throw new ArgumentNullException("dictionaries");
            }
            if (selectedDictionary == null)
            {
                throw new ArgumentNullException("selectedDictionary");
            }
            if (!dictionaries.Contains(selectedDictionary))
            {
                throw new ArgumentException("The selectedDictionary is not an item in the supplied dictionaries collection");
            }

            Dictionaries = new ObservableCollection<IBoggleDictionary>(dictionaries);
            SelectedDictionary = selectedDictionary;
            DataContext = this;
            InitializeComponent();
        }

        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
            Close();
        }

        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }
    }
}
